1
|
|
|
// Third Party Libraries |
2
|
|
|
require('./bootstrap'); |
3
|
|
|
require('jquery-easing'); |
4
|
|
|
require('datatables.net-bs4'); |
5
|
|
|
require('dropzone'); |
6
|
|
|
require('select2'); |
7
|
|
|
//require('clipboard'); |
8
|
|
|
|
9
|
|
|
$(document).ready(function() |
10
|
|
|
{ |
11
|
|
|
// Enable any tooltips on the page |
12
|
|
|
initTooltip(); |
13
|
|
|
}); |
14
|
|
|
|
15
|
|
|
// Initialize any tooltips on the page |
16
|
|
|
function initTooltip() |
17
|
|
|
{ |
18
|
|
|
$('[data-tooltip="tooltip"]').tooltip(); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/////////////////////////// Drag and Drop/File Upload Functions //////////////////////////////////// |
22
|
|
|
// Initialize drag and drop for only one file |
23
|
|
|
function fileDrop(form) |
24
|
|
|
{ |
25
|
|
|
// Initialize Drag and Drop |
26
|
|
|
var drop = $('#dropzone-box').dropzone( |
|
|
|
|
27
|
|
|
{ |
28
|
|
|
url: form.attr('action'), |
29
|
|
|
autoProcessQueue: false, |
30
|
|
|
maxFilesize: maxUpload, |
|
|
|
|
31
|
|
|
uploadMultiple: false, |
32
|
|
|
parallelUploads: 1, |
33
|
|
|
maxFiles: 1, |
34
|
|
|
addRemoveLinks: true, |
35
|
|
|
init: function() |
36
|
|
|
{ |
37
|
|
|
var myDrop = this; |
38
|
|
|
form.on('submit', function(e, formData) |
|
|
|
|
39
|
|
|
{ |
40
|
|
|
e.preventDefault(); |
41
|
|
|
myDrop.processQueue(); |
42
|
|
|
$('#forProgressBar').show(); |
43
|
|
|
$('.submit-button').attr('disabled', true); |
44
|
|
|
}); |
45
|
|
|
this.on('sending', function(file, xhr, formData) |
46
|
|
|
{ |
47
|
|
|
var formArray = form.serializeArray(); |
48
|
|
|
$.each(formArray, function() |
49
|
|
|
{ |
50
|
|
|
formData.append(this.name, this.value); |
51
|
|
|
}); |
52
|
|
|
}); |
53
|
|
|
this.on('totaluploadprogress', function(progress) |
54
|
|
|
{ |
55
|
|
|
$("#progressBar").css("width", Math.round(progress)+"%"); |
56
|
|
|
$("#progressStatus").text(Math.round(progress)+"%"); |
57
|
|
|
console.log(progress); |
|
|
|
|
58
|
|
|
}); |
59
|
|
|
this.on('reset', function() |
60
|
|
|
{ |
61
|
|
|
$('#form-errors').addClass('d-none'); |
62
|
|
|
}); |
63
|
|
|
this.on('success', function(files, response) |
64
|
|
|
{ |
65
|
|
|
uploadComplete(response); |
66
|
|
|
}); |
67
|
|
|
this.on('error', function(file, response) |
68
|
|
|
{ |
69
|
|
|
uploadFailed(response); |
70
|
|
|
}); |
71
|
|
|
} |
72
|
|
|
}); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
// Initialize drag and drop for multiple file uploads |
76
|
|
|
function multiFileDrop(form) |
77
|
|
|
{ |
78
|
|
|
// Initialize Drag and Drop |
79
|
|
|
var drop = $('#dropzone-box').dropzone( |
|
|
|
|
80
|
|
|
{ |
81
|
|
|
url: form.attr('action'), |
82
|
|
|
autoProcessQueue: false, |
83
|
|
|
uploadMultiple: true, |
84
|
|
|
parallelUploads: 10, |
85
|
|
|
maxFiles: 10, |
86
|
|
|
maxFilesize: maxUpload, |
|
|
|
|
87
|
|
|
addRemoveLinks: true, |
88
|
|
|
init: function() |
89
|
|
|
{ |
90
|
|
|
var myDrop = this; |
91
|
|
|
form.on('submit', function(e, formData) |
|
|
|
|
92
|
|
|
{ |
93
|
|
|
e.preventDefault(); |
94
|
|
|
if(myDrop.getQueuedFiles().length > 0) |
95
|
|
|
{ |
96
|
|
|
myDrop.processQueue(); |
97
|
|
|
$('#forProgressBar').show(); |
98
|
|
|
$('.submit-button').attr('disabled', true); |
99
|
|
|
} |
100
|
|
|
else |
101
|
|
|
{ |
102
|
|
|
$.post(form.attr('action'), form.serialize(), function(data) |
103
|
|
|
{ |
104
|
|
|
uploadComplete(data); |
105
|
|
|
}); |
106
|
|
|
} |
107
|
|
|
}); |
108
|
|
|
this.on('sendingmultiple', function(file, xhr, formData) |
109
|
|
|
{ |
110
|
|
|
var formArray = form.serializeArray(); |
111
|
|
|
$.each(formArray, function() |
112
|
|
|
{ |
113
|
|
|
formData.append(this.name, this.value); |
114
|
|
|
}); |
115
|
|
|
}); |
116
|
|
|
this.on('totaluploadprogress', function(progress) |
117
|
|
|
{ |
118
|
|
|
$("#progressBar").css("width", Math.round(progress)+"%"); |
119
|
|
|
$("#progressStatus").text(Math.round(progress)+"%"); |
120
|
|
|
console.log(progress); |
|
|
|
|
121
|
|
|
}); |
122
|
|
|
this.on('reset', function() |
123
|
|
|
{ |
124
|
|
|
$('#form-errors').addClass('d-none'); |
125
|
|
|
}); |
126
|
|
|
this.on('successmultiple', function(files, response) |
127
|
|
|
{ |
128
|
|
|
this.removeAllFiles(true); |
129
|
|
|
uploadComplete(response); |
130
|
|
|
}); |
131
|
|
|
this.on('errormultiple', function(file, response) |
132
|
|
|
{ |
133
|
|
|
uploadFailed(response); |
134
|
|
|
}); |
135
|
|
|
} |
136
|
|
|
}); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
// Reset the progress bar and drag and drop box |
140
|
|
|
function resetProgressBar() |
141
|
|
|
{ |
142
|
|
|
$('#dragndrop-notice').text('Or Drag Files Here'); |
143
|
|
|
$('#progressBar').css('width', '0%').attr('aria-valuenow', 0); |
144
|
|
|
$('#progressStatus').text(''); |
145
|
|
|
$('#forProgressBar').hide(); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
// Reset the Edit Modal to its default state |
149
|
|
|
function resetEditModal() |
150
|
|
|
{ |
151
|
|
|
$('#edit-modal').modal('hide'); |
152
|
|
|
$('#edit-modal').find('.modal-title').text(''); |
153
|
|
|
$('#edit-modal').find('.modal-body').text(''); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
////////////////////////////////////////////////////////////////////////////////////////// |
157
|
|
|
|
158
|
|
|
// Make the functions in this file globally accessable |
159
|
|
|
window.resetProgressBar = resetProgressBar; |
160
|
|
|
window.resetEditModal = resetEditModal; |
161
|
|
|
window.fileDrop = fileDrop; |
162
|
|
|
window.multiFileDrop = multiFileDrop; |
163
|
|
|
|